package com.example.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class SomeService {

    private static final Logger logger = LoggerFactory.getLogger(SomeService.class);

    @Autowired
    private RedisTemplate<String, Object> redisTemplate; // 默认 Redis 实例

    @Autowired
    @Qualifier("activityRedisTemplate")
    private RedisTemplate<String, Object> activityRedisTemplate; // 活动 Redis 实例

    @Autowired
    @Qualifier("sessionRedisTemplate")
    private RedisTemplate<String, Object> sessionRedisTemplate; // 会话 Redis 实例

    @Autowired
    @Qualifier("pkGameRedisTemplate")
    private RedisTemplate<String, Object> pkGameRedisTemplate; // PKGame Redis 实例

    public void someMethod() {
        // 设置值并且获取新值
        logger.info("设置并获取默认 Redis 实例中的 key1");
        redisTemplate.opsForValue().set("key1", "value1");
        String value1 = (String) redisTemplate.opsForValue().get("key1");
        logger.info("获取到的 key1 的值: {}", value1);

        logger.info("设置并获取活动 Redis 实例中的 key2");
        activityRedisTemplate.opsForValue().set("key2", "value2");
        String value2 = (String) activityRedisTemplate.opsForValue().get("key2");
        logger.info("获取到的 key2 的值: {}", value2);

        logger.info("设置并获取会话 Redis 实例中的 key3");
        sessionRedisTemplate.opsForValue().set("key3", "value3");
        String value3 = (String) sessionRedisTemplate.opsForValue().get("key3");
        logger.info("获取到的 key3 的值: {}", value3);

        logger.info("设置并获取 PKGame Redis 实例中的 key4");
        pkGameRedisTemplate.opsForValue().set("key4", "value4");
        String value4 = (String) pkGameRedisTemplate.opsForValue().get("key4");
        logger.info("获取到的 key4 的值: {}", value4);
    }
}
